package edu.sias.hyzn.service.impl;

import edu.sias.common.utils.SecurityUtils;
import edu.sias.hyzn.mapper.DoctorMapper;
import edu.sias.hyzn.service.IDoctorService;
import edu.sias.hyzn.vo.DoctorInfo;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DoctorService implements IDoctorService {

    private final DoctorMapper doctorMapper;

    public DoctorService(DoctorMapper doctorMapper) {
        this.doctorMapper = doctorMapper;
    }

    @Override
    public List<DoctorInfo> selectDoctorList(DoctorInfo doctorInfo) {
        return doctorMapper.selectDoctorList(doctorInfo);
    }

    @Override
    public int updateDoctorInfo(DoctorInfo doctorInfo) {
        return doctorMapper.updateDoctorInfo(doctorInfo);
    }

    @Override
    public int insertDoctorInfo(DoctorInfo doctorInfo) {
        Long userId = SecurityUtils.getUserId();
        doctorInfo.setId(userId);
        DoctorInfo findDoctor = doctorMapper.selectDoctorInfoByUserId(userId);
        if (findDoctor != null){
            return 0;
        }
        return doctorMapper.insertDoctorInfo(doctorInfo);
    }

    @Override
    public DoctorInfo getDoctorInfo() {
        Long userId = SecurityUtils.getUserId();
        return doctorMapper.selectDoctorInfoByUserId(userId);
    }

}
